package com.atguigu.oshi.demos.service;

import org.springframework.stereotype.Service;
import oshi.SystemInfo;
import oshi.hardware.CentralProcessor;

/**
 * @program: oshi
 * @description:
 * @author: Mr.Yan
 * @create: 2024-12-08 16:35
 **/
@Service
public class CpuLoadService {
//返回CPU的负载信息
public double[] getCpuLoad() {
 SystemInfo si = new SystemInfo();
 CentralProcessor processor = si.getHardware().getProcessor();
 //返回CPU的负载信息，1000表示1秒采样一次
 double[] processorCpuLoad = processor.getProcessorCpuLoad(1000);
 //返回CPU的平均负载
 return processorCpuLoad;
}
}
